/**
 * 文本动态变化类
 */
export default class LableChange {
  /**绑定的文本 */
  public lable: cc.Label;
  /**数量 */
  public count: number;
  public name: string;
  isValid: boolean;
  /**金币前缀 */
  private _prefix: string = "$";

  public maxCount: number;
  public constructor(lable: cc.Label) {
    this.lable = lable;
    this.count = 0;
  }

  public setData(maxCount: number): void {
    this.maxCount = maxCount;
  }


  public get num(): number {
    return 0;
  }
  private _count: number = 0;
  /**
   * 动态设置金币增长
   */
  public set num(value: number) {
    if (!this.lable) {
      return;
    }

    let cha: number = this.maxCount - this.count;
    let num: number = Math.floor(cha * value);
    this.lable.string = this._prefix + (Math.floor(this.count + num)) + ".00";
    if (value == 1) {
      this.count = this.maxCount;
    }

  }

  /**设置前缀 */
  public set prefix(string: string) {
    if (string) {
      this._prefix = string;
    }
  }

  public get prefix(): string {
    return this._prefix;
  }


  private tween: cc.Tween;
  /**播放金币增长动画 */
  public play(count: number, time: number, callBack?: Function, thisObj?: any) {
    this.maxCount = count;
    // cc.Tween.stopAllByTarget(this)
    // this["stopAllActions"]();
    if (this.tween) {
      this.tween.stop();
    }
    this.tween = cc.tween(this).to(time, { num: 1 }).start();

  }

  /**销毁 */
  public destroy(): boolean {
    if (this.tween) {
      this.tween.stop();
    }
    this.lable = null;
    this.count = null;
    this.maxCount = null;
    return
  }

}